unit JATUIF_Driver_Sound;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, MMSystem, BASS;

type

    { TSoundDriver }

    TSoundDriver = class
      Public
        Constructor Create(SoundFile:String);
        Procedure Play;
        Procedure Stop;
      Private
        isMod: Boolean;
        Chan, Pos:DWORD;
        Sound_File: String;
    end;

implementation

constructor TSoundDriver.Create(SoundFile:String);
begin
     Sound_File:= SoundFile;
     inherited Create;
end;

procedure TSoundDriver.Play;
begin
     Try
        if not BASS_Init(-1,44100,0,0,nil) then begin
           //Failed to Init Channel.
        end;
        chan := BASS_StreamCreateFile(FALSE, PChar(Sound_File), 0, 0, BASS_SAMPLE_LOOP {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});
        if (chan = 0) then
           chan := BASS_StreamCreateURL(PAnsiChar(AnsiString(Sound_File)), 0, BASS_SAMPLE_LOOP, nil, nil);
        if (chan <> 0) then begin
           pos := BASS_ChannelGetLength(chan, BASS_POS_BYTE);
        end else begin
            chan := BASS_MusicLoad(FALSE, PChar(Sound_File), 0, 0, BASS_MUSIC_LOOP or BASS_MUSIC_RAMPS or BASS_MUSIC_PRESCAN {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF}, 1);
        end;
        BASS_ChannelPlay(chan, False);
     Except
           //Exception Thrown.
     end;
end;

procedure TSoundDriver.Stop;
begin
     Try
        BASS_ChannelStop(chan);
     Except
           //Exception Stuffs
     end;
end;

end.

